package net.sxnic.ugr.menu;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sxinfo.core.dao.Page;
import net.sxinfo.core.spring25.Dao;
import net.sxinfo.core.spring25.DefaultManager;
import net.sxnic.ugr.menu.dao.MenuDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("menuManager")
public class DefaultMenuManager extends DefaultManager<Menu, MenuDao, String>
		implements MenuManager {

	@Autowired
	private MenuDao menuDao;

	public Page getMenus(int page, int pageSize, String orderProperty,
			boolean asc) {
		return menuDao.getPage(page, pageSize, orderProperty, asc);
	}

	public List<Menu> getAllByLevel() {
		return menuDao.getAllByLevel();
	}

	public List<Menu> getAllByOrder() {
		return menuDao.getAllByOrder();
	}

	public Page getAllByOrder(int page, int pageSize, String orderProperty,
			boolean asc) {
		return menuDao.getPage(page, pageSize, orderProperty, asc);
	}

	public List<Menu> getSubLevel(String parentMenuCode) {
		return menuDao.getSubLevel(parentMenuCode);
	}

	public List<Menu> getTopLevel() {
		return menuDao.getTopLevel();
	}

	@Override
	protected Dao<Menu, String> getEntityDao() {
		return menuDao;
	}

	@Override
	public Map<String, Menu> findMap() {
		List<Menu> list = getAll();
		Map<String, Menu> map = new HashMap<String, Menu>();
		
		for(Menu m:list){
			map.put(m.getCode(), m);
		}
		return map;
	}
	
	@Override
	public Map<String, String> findMap1() {
		List<Menu> list = menuDao.getAllmenus();
		Map<String, String> map = new HashMap<String, String>();
		
		for(Menu m:list){
			map.put(m.getCode(), m.getValue());
		}
		return map;
	}
	
	
	public Menu getMenuByCode(String code) {
		return menuDao.findByUnique("code", code);
	}
	
	
	public Menu getMenuById(String Id) {
		return menuDao.get(Id);
	}

	@Override
	public List<Menu> getTopList() {
		return menuDao.getTopLevel();
	}

	@Override
	public List<Menu> getChildList(String root) {
		// TODO Auto-generated method stub
		return menuDao.getChildList(root);
	}
	
	 
 

}
